<?php
	$xtpl_main->assign ( "page_title", "Home" );
	//--
	if (isset ( $_GET ['cate'] )) {
		$cate = intval($_GET ['cate']);
	}
	$query = "
					SELECT m.movie_id, m.movie_name, m.movie_image, m.movie_description, m.movie_price, m.movie_trailer 
					FROM movie m 
					INNER JOIN category c ON m.cate_id = c.cate_id 
					WHERE m.movie_status = '1' AND c.cate_status = '1' 
				 ";
	
	if (isset ( $cate )) {
		$query = $query . "AND m.cate_id = '" . $cate . "'";
	}
	$query = $query . " ORDER BY m.movie_id DESC";
	
	$result = mysql_query ( $query );
	if (@mysql_num_rows ( $result ) > 0) {
		$counter = 1;
		while ( $row = mysql_fetch_array ( $result ) ) {
			if ($counter % 2) {
				$row ['row_class'] = 'class="leftbox"';
			} else {
				$row ['row_class'] = 'class="rightbox"';
				$row ['row_br'] = '<div class="clear br"></div>';
			}
			
			if (isset ( $_SESSION ['member_id'] ) && $_SESSION ['member_id'] != '') {
				$row['movie_buynow'] = "?mod=member&act=shoppingcart&mid=".$row['movie_id'];
			} else {
				$row['movie_buynow'] = "?mod=member&act=login&mid=".$row['movie_id'];
			}

			if($row['movie_image'] != '' && file_exists(ROOT_PATH.'upload/thumb'.$row['movie_image'])){
				$row['movie_image'] = BASE_URL.'upload/thumb'.$row['movie_image'];
			}else{
				$row['movie_image'] = BASE_URL.'upload/default.jpg';
			}
			
			$counter ++;
			//--
			$xtpl->assign ( 'list_movie', $row );
			$xtpl->parse ( "center.list_movie" );
		}
	} else {
		$xtpl->parse ( "center.no_movie" );
	}
?>
